package com.gold.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class GridPage<T> implements Serializable{
	
	private static final long serialVersionUID = 1L;
	
	public final static Logger logger = LoggerFactory.getLogger(GridPage.class);
	
	private long page = 1; //当前页
	
	//private long total = 1; //总页数
	
	//private long records = 1; //总记录数
	
	//private List<T> rows = new ArrayList<T>();
	
	//适应liguerUi的grid
	private long Total=1;
	private List<T> Rows = new ArrayList<T>();
	
	
	
	
	public long getTotal() {
		return Total;
	}

	public void setTotal(long total) {
		Total = total;
	}

	public List<T> getRows() {
		return Rows;
	}

	public void setRows(List<T> rows) {
		Rows = rows;
	}

	public long getPage() {
		return page;
	}
	
	public void setPage(long page) {
		this.page = page;
	}

/*	public long getTotal() {
		return total;
	}
	
	public void setTotal(long total) {
		this.total = total;
	}
	
	public long getRecords() {
		return records;
	}
	
	public void setRecords(long records) {
		this.records = records;
	}
	
	public List<T> getRows() {
		return rows;
	}
	
	public void setRows(List<T> rows) {
		this.rows = rows;
	}*/
	
	public GridPage(Page<T> pageInfo) {
		setPage(pageInfo.getPageNo());
		this.setTotal(pageInfo.getTotalRecord());
		setTotal(pageInfo.getTotalPage());
		List<T> list = pageInfo.getResults();
		setRows(list);
	}
	
	public GridPage(List<T> list) {
		setTotal(list.size());
		setRows(list);
	}
	
	public GridPage(long records, long page, int rowsOfPage) {
		setTotal(records);
		setPage(page);
		//setTotal((getRecords()%rowsOfPage == 0)?(getRecords()/rowsOfPage):(getRecords()/rowsOfPage+1));
	}
	
	public GridPage() {
		super();
	}
	
	public long getStartOfThisPage(int rowsOfPage){
		return (page-1)*rowsOfPage + 1;
	}
	
	public long getEndOfThisPage(int rowsOfPage) {
		return page * rowsOfPage ;
	}
}
